<template>
	<el-dialog title="编辑序号" :visible.sync="show" width="400px">
		<el-form :model="form" ref="form">
			<el-form-item label="序号" :label-width="formLabelWidth">
				<el-input v-model="form.sort" type="number" autocomplete="off"></el-input>
			</el-form-item>
		</el-form>
		<div slot="footer" class="dialog-footer">
			<el-button @click="show = false">取 消</el-button>
			<el-button type="primary" @click="submitForm('form')" :loading="submitting">{{ submitText }}</el-button>
		</div>
	</el-dialog>
</template>

<script>
	const txt = "确 定";
	import {
		updateSort
	} from "@/api/oldCityFind/index.js";
	export default {
		data() {
			return {
				show: false,
				formLabelWidth: '40px',
				form: {
					oldCityId: '',
					sort: 1000
				},
				submitting: false,
				submitText: txt
			}
		},
		methods: {
			submitForm(formName) {
				this.$refs[formName].validate((valid) => {
					if (valid) {
						this.submitting = true;
						this.submitText = "提交中";
						this.save();
					} else {
						return false;
					}
				});
			},
			async save() {
				this.form.sort = this.form.sort>=0 ? this.form.sort : 1000;
				try {
					const req = updateSort(this.form);
					const res = await req;
					setTimeout(() => {
						this.$emit("update");
						this.show = false;
					}, 500);
				} catch (error) {}
				this.submitText = txt;
				this.submitting = false;
			}
		}
	}
</script>

<style scoped>

</style>
